/*
    This file is part of vlbi2.

    vlbi2 is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    vlbi2 is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with vlbi2.  If not, see <http://www.gnu.org/licenses/>.

#========================================================================
#
# Alan Rogers
# Massachusetts Institute of Technology Haystack Observatory
# Program: vlbi2
# Calculate cross or autocorrelation spectra from Mk5b recorded data.
#
# The vlbi2 program is used to correlate two Mark 5B files with the same
# starting record time and record mode. A postscript file dd1.pos is
# produced showing the correlation amplitude and phase as a function
# of frequency in all channels in the two files with all channels
# plotted on the same axes. Correlation coefficients (fringe amplitudes,
# which will be 1.00 for an autocorrelation) are indicated below each
# channel. The vlbi2 program accepts two files, each 10 MB in size,
# and two flags. The usage is:
#
#        vlbi2 <file1> <file2> [-2bit <2bit_arg>] [-rev <rev_arg>]
#
# Where the items in [] are optional. The -2bit flag indicates whether
# the files are 2 bits/sample recordings (2bit_arg is 1) or 1 bit/sample
# (2bit_arg is 0) [default]. The files must be the same number of
# bits per sample. The .rev flag determines whether the channels in dd1.pos
# are plotted in reverse order (rev_arg is 1) or normal order
# (rev_arg is 0) [default]. It is important to note that with the .rev
# flag, though the channels can be plotted in the reverse order, they
# are not flipped in frequency. If file1 and file2 are the same, an
# autocorrelation is produced; if they are different a cross correlation
# is produced.
#
#
#=======================================================================
#
# Dec 2010
# S.Weston              stuart.weston@aut.ac.nz
# AUT University
#
# Modified to use DISLIN so that we can see the data better than just
# printed across the bottom of an A4 sheet in postscript. Also use
# DISLIN widgets to provide a better UI.
#
#=======================================================================
*/

#include <stdio.h>
#include <math.h>
#include "vlbi2.h"

float FindMax(float Val[])
{
    int n;
    float Max = Val[0];

    for (n = 1; n < NSIZ2; n++) {
        if (Val[n] > Max) Max = Val[n];
    }
    return Max;
}

float FindMin(float Val[])
{
    int n;
    float Min = Val[0];

    for (n = 1; n < NSIZ2; n++) {
        if (Val[n] <  Min) Min = Val[n];
    }
    return Min;
}

double DFindMax(double Val[])
{
    int n;
    double Max = Val[0];

    for (n = 1; n < NFRQSER*NSIZ2; n++) {
        if (Val[n] > Max) Max = Val[n];
    }
    return Max;
}

double DFindMin(double Val[])
{
    int n;
    double Min = Val[0];

    for (n = 1; n < NFRQSER*NSIZ2; n++) {
        if (Val[n] <  Min) Min = Val[n];
    }
    return Min;
}

void LogAxisScale()
{

  xscl[0]=(float)DFindMin(xspecr);
  xscl[1]=(float)DFindMax(xspecr);

  if(verbose==1){
     printf("Max xspeca %f\n",DFindMax(xspeca));
     printf("Min xspeca %f\n",DFindMin(xspeca));
     printf("Max xspecr %f\n",DFindMax(xspecr));
     printf("Min xspecr %f\n",DFindMin(xspecr));
  }

}
